package model;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;


public class EventModel implements java.io.Serializable {
	private int minCapacity, maxCapacity, id, venueId,numberOfSignedUpUsers;
	private String eventName, description, venueName, startTime, deadline, date, time;
	private ArrayList<UserModel> signedUpUsers;
	private Calendar calendarStarttime=null;
	private Calendar calendarDeadline=null;
	
	public EventModel(){
		this.minCapacity = -1;
		this.maxCapacity = -1;
		this.id = -1;
		this.venueId = -1;
		this.startTime = null;
		this.deadline = null;
		this.eventName = "";
		this.description = "";
		this.venueName = "";
		this.signedUpUsers = new ArrayList<UserModel>();
	}
	/**
	 * @param minCapacity
	 * @param maxCapacity
	 * @param id
	 * @param venueId
	 * @param startTime
	 * @param deadline
	 * @param eventName
	 * @param description
	 * @param venueName
	 * @param signedUpUsers
	 */
	public EventModel(int minCapacity, int maxCapacity, int id, int venueId, String startTime, String deadline, String eventName, String description, String venueName, ArrayList<String>signedUpUsers)
	{
		this.minCapacity = minCapacity;
		this.maxCapacity = maxCapacity;
		this.id = id;
		this.venueId = venueId;
		this.startTime = startTime;
		this.deadline = deadline;
		this.eventName = eventName;
		this.description = description;
		this.venueName = venueName;
		
	}
	
	public Calendar getCalendarStarttime() {
		return calendarStarttime;
	}
	public void setCalendarStarttime(Calendar calendarStarttime) {
		this.calendarStarttime = calendarStarttime;
	}
	public Calendar getCalendarDeadline() {
		return calendarDeadline;
	}
	public void setCalendarDeadline(Calendar calendarDeadline) {
		this.calendarDeadline = calendarDeadline;
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}

	public ArrayList<UserModel> getSignedUpUsers() {
		return signedUpUsers;
	}

	public void setSignedUpUsers(ArrayList<UserModel> signedUpUsers2) {
		this.signedUpUsers = signedUpUsers2;
	}

	public void setMinCapacity(int minCapacity) {
		this.minCapacity = minCapacity;
	}

	public void setMaxCapacity(int maxCapacity) {
		this.maxCapacity = maxCapacity;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setVenueId(int venueId) {
		this.venueId = venueId;
	}

	public void setEventName(String eventName) {
		this.eventName = eventName;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setVenueName(String venueName) {
		this.venueName = venueName;
	}

	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}

	public void setDeadline(String deadline) {
		this.deadline = deadline;
	}

	public int getMinCapacity() {
		return minCapacity;
	}
	
	public String getMinCapacityString() {
		return ""+minCapacity;
	}
	
	// checks if user is already signed up
	public boolean checkUser(String username) {
		for(int i=0; i < signedUpUsers.size(); i++) {
			if(signedUpUsers.get(i).equals(username)) return true;
		}
		return false;
	}

	public int getMaxCapacity() {
		return maxCapacity;
	}
	
	public boolean hasMaxCapacity() {
		return maxCapacity > 0;
	}
	
	public String getMaxCapacityString() {
		return ""+maxCapacity;
	}
	
	public int getId() {
		return id;
	}
	
	public String getIdString() {
		return ""+id;
	}
	
	public int getVenueId() {
		return venueId;
	}

	public String getVenueIdString() {
		return ""+venueId;
	}
	
	public String getStartTime() {
		return startTime;
	}

	public String getDeadline() {
		return deadline;
	}

	public String getEventName() {
		return eventName;
	}

	public String getDescription() {
		return description;
	}

	public String getVenueName() {
		return venueName;
	}
	public String getStatus(){
		String status="fail";
		if(deadlineHasPassed()) {
			status="closed - active";
			if(getNumberOfSignedUpUsers()<getMinCapacity()){
				status="cancelled";
			}
		}
		else{
			status="active";
			if(getMaxCapacity()!=-1){
				if(getNumberOfSignedUpUsers()<getMinCapacity()){
					status="possible";
				}
				else if(getNumberOfSignedUpUsers()==getMaxCapacity()){
					status="full";
				}
			}
			else{
				if(getNumberOfSignedUpUsers()<getMinCapacity()){
					status="possible";
				}
			}
		}
		return status;
	}
	
	public boolean deadlineHasPassed(){
		Calendar now = Calendar.getInstance();
		if( getCalendarDeadline().compareTo(now)<=0){
			//The deadline has passed
			return true;
		}
		else return false;
	}

	public int getNumberOfSignedUpUsers() {
		return numberOfSignedUpUsers;
	}

	public void setNumberOfSignedUpUsers(int numberOfSignedUpUsers) {
		this.numberOfSignedUpUsers = numberOfSignedUpUsers;
	}
}
